package com.wdj.creation.singleton.lazySingleton;

import com.wdj.creation.singleton.staticfactory.Singleton;

/**
 * @ClassName LazySingleton2
 * @Description
 * @Author wdj
 * @Date 2020/8/22 10:01
 * @Version 1.0
 **/
public class LazySingleton2 {
    private static LazySingleton2 str = null;

    private LazySingleton2(){}
    // 双重检查锁定
    public  static LazySingleton2 getInstance(){
        //  第一重判断
        if(str == null){
            //  锁定代码块
            synchronized (LazySingleton2.class){
                //  第二重判断
                if(str == null){
                    str = new LazySingleton2();
                }
            }
        }
        return str;
    }
    public static void main(String[] args) {
        LazySingleton2 singleton1 = LazySingleton2.getInstance();
        LazySingleton2 singleton2 = LazySingleton2.getInstance();
        System.out.println(singleton1 == singleton2);
        System.out.println(singleton1.equals(singleton2));

    }
}
